/**
 * 环境配置 - 编译时配置
 * 根据编译指令确定环境配置
 */

// 编译时环境检测
const isProductionBuild = process.env.NODE_ENV === 'production' || process.env.BUILD_ENV === 'production';

export interface EnvironmentConfig {
  isProduction: boolean;
  database: {
    host: string;
    port: number;
    username: string;
    password: string;
    database: string;
  };
  redis: {
    host: string;
    port: number;
    password: string;
    db: number;
  };
}

// 生产环境配置
const productionConfig: EnvironmentConfig = {
  isProduction: true,
  database: {
    host: '127.0.0.1',
    port: 3306,
    username: 'root',
    password: 'yEAiRE2jcxTyRBy5',
    database: 'nextjs',
  },
  redis: {
    host: '127.0.0.1',
    port: 6379,
    password: '',
    db: 0,
  },
};

// 开发/测试环境配置
const developmentConfig: EnvironmentConfig = {
  isProduction: false,
  database: {
    host: '43.143.253.188',
    port: 3306,
    username: 'nextjs',
    password: 'yEAiRE2jcxTyRBy5',
    database: 'nextjs',
  },
  redis: {
    host: '43.143.253.188',
    port: 6379,
    password: 'jack666',
    db: 0,
  },
};

// 根据编译时环境选择配置
export const environmentConfig: EnvironmentConfig = isProductionBuild ? productionConfig : developmentConfig;

// 导出配置信息
export const configInfo = {
  environment: environmentConfig.isProduction ? 'production' : 'development',
  database: {
    host: environmentConfig.database.host,
    port: environmentConfig.database.port,
    database: environmentConfig.database.database,
  },
  redis: {
    host: environmentConfig.redis.host,
    port: environmentConfig.redis.port,
  },
};

// 打印配置信息
if (process.env.NODE_ENV !== 'test') {
  console.log('🔧 编译时环境配置:');
  console.log(`   环境: ${configInfo.environment}`);
  console.log(`   数据库: ${configInfo.database.host}:${configInfo.database.port}/${configInfo.database.database}`);
  console.log(`   Redis: ${configInfo.redis.host}:${configInfo.redis.port}`);
  console.log('');
}